package com.atguigu.factory.aNoUseFactory.order;

import com.atguigu.factory.aNoUseFactory.pizza.CheesePizza;
import com.atguigu.factory.aNoUseFactory.pizza.GreekPizza;
import com.atguigu.factory.aNoUseFactory.pizza.PepperPizza;
import com.atguigu.factory.aNoUseFactory.pizza.Pizza;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @program: design-patterns
 * @author: yangshen
 * @description: 订购披萨
 * @create: 2022-01-18 21:44
 **/
public class OrderPizza {
    /**
     * 构造器
     */
    public OrderPizza() {
        Pizza pizza = null;
        do {
            String orderType = getOrderType();
            if ("greek".equals(orderType)){
                pizza = new GreekPizza();
                pizza.setName("希腊披萨");
            }else if ("cheese".equals(orderType)){
                pizza = new CheesePizza();
                pizza.setName("奶酪披萨");
            }else if ("pepper".equals(orderType)){
                //当新增一个披萨时，这里进行了代码修改
                pizza = new PepperPizza();
                pizza.setName("胡椒披萨");
            }else {
                break;
            }
            //输出pizza的制作过程
            pizza.prepare();
            pizza.bake();
            pizza.cut();
            pizza.box();
        }while (true);
    }

    /**
     * 写一个方法，可以获取客户希望订购的披萨种类
     * @return 披萨种类
     */
    public String getOrderType(){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("--------------------------");
        System.out.println("input pizza 种类：");

        try {
            String s = reader.readLine();
            return s;
        } catch (IOException e) {
            e.printStackTrace();
            return "";
        }

    }
}
